package simple.framework.util;

import java.io.*;
import java.lang.System;
import javax.servlet.http.*;

public abstract class jpage
{
  public conf conf;
  public String eMessage;
  public Long pageStartTimeMillis;
  public Long pageEndTimeMillis;
  public Long pageRunTimeMillis;

  public void PageAutoRedirect()
  {
    String tNURLPre = conf.getNURLPre();
    String tServerName = cls.getLRStr(tNURLPre, "/", "right");
    Integer tAutoRedirect = cls.getNum(conf.sp.itake("global.config.autoredirect", "cfg"), 0);
    if (tAutoRedirect == 1)
    {
      if (!cls.isEmpty(tServerName))
      {
        tServerName = tServerName.toLowerCase();
        if (cls.getLRStr(tServerName, ".", "left") != "www")
        {
          String tNewServerName = "www." + tServerName;
          tNURLPre = tNURLPre.toLowerCase();
          tNURLPre = tNURLPre.replace(tServerName, tNewServerName);
          String tRedirectURL = tNURLPre + conf.getNURI();
          if (cls.getLRStr(tRedirectURL, "/", "right").toLowerCase().equals("default.jsp")) tRedirectURL = cls.getLRStr(tRedirectURL, "/", "leftr") + "/";
          if (!cls.isEmpty(conf.getNURS())) tRedirectURL = tRedirectURL + "?" + conf.getNURS();
          conf.response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
          conf.response.setHeader("Location", tRedirectURL);
        }
      }
    }
  }

  public void Init(Object argRequest, Object argResponse) 
  {
    Object tRequest = argRequest;
    Object tResponse = argResponse;
    conf = new conf();
    conf.Init(tRequest, tResponse);
  }

  public void PageInit()
  {
    PageAutoRedirect();
    pageStartTimeMillis = System.currentTimeMillis();
    conf.ntitle = conf.sp.itake("global.default.web_title", "lng");
    conf.navSpStr = conf.sp.itake("global.config.navspstr", "cfg");
    conf.ntitleSpStr = conf.sp.itake("global.config.ntitlespstr", "cfg");
  }

  public void PageNoCache()
  {
    conf.response.setDateHeader("Expires", 0);
    conf.response.setHeader("Cache-Control", "no-cache");
  }

  public void PagePrint(String argString)
  {
    Boolean tbool = true;
    String tString = argString;
    Integer tAutoRedirect = cls.getNum(conf.sp.itake("global.config.autoprintcopyright", "cfg"), -1);
    if (tAutoRedirect != -1) tbool = false;
    else
    {
      if (!cls.isEmpty(tString))
      {
        if (tString.length() < conf.ajaxPreContent.length()) tbool = false;
        else
        {
          if (tString.substring(0, conf.ajaxPreContent.length()).equals(conf.ajaxPreContent)) tbool = false;
        }
      }
    }
    if (tbool)
    {
      pageEndTimeMillis = System.currentTimeMillis();
      pageRunTimeMillis = pageEndTimeMillis - pageStartTimeMillis;
      tString += "\r\n<!--JTBC(2.0), Processed in " + pageRunTimeMillis + " ms-->";
    }
    try
    {
      PrintWriter tPrintWriter = conf.response.getWriter();
      tPrintWriter.print(tString);
      tPrintWriter.close();
    }
    catch(Exception e) {}
  }

  public void PageClose()
  {
    pageEndTimeMillis = System.currentTimeMillis();
    pageRunTimeMillis = pageEndTimeMillis - pageStartTimeMillis;
  }
}